<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	template="/layout/base.xhtml"
	xmlns:sec="http://www.springframework.org/security/tags"
	xmlns:honorato="http://java.sun.com/jsf/composite/honorato">

	<ui:define name="bodyPrincipal">

		<h:panelGroup layout="block">

			<h:panelGroup layout="block" style="text-align:left">
				<h:outputText value="Incluir Usuário" />
			</h:panelGroup>
			<ui:include src="/layout/ajaxStatus.xhtml"  />

			<h:form prependId="false" id="insertUserForm">

				<p:outputPanel autoUpdate="true">
					<p:messages id="mensagens" showDetail="true" showSummary="true" />
				</p:outputPanel>

				<h:panelGroup layout="block">

					<h:panelGrid columns="3" cellspacing="3" cellpadding="3">

						<h:outputLabel value="Login" />
						
						<p:inputText id="userLogin" value="#{userBean.user.login}" size="50" maxlength="100" />
						<h:message for="userLogin" style="color:red" />

						<h:outputLabel value="Nome" />
						<p:inputText id="userName" value="#{userBean.user.name}" size="50" maxlength="100" />
						<h:message for="userName" style="color:red" />

						<h:outputLabel value="Status" />
						<h:selectOneRadio id="userStatus" value="#{userBean.user.status}" 
						disabled="#{empty userBean.user.idUser}">
						
						<f:selectItems value="#{userBean.userStatusList()}" 
							var="userStatus" itemLabel="#{userStatus.label}"
							itemValue="#{userStatus}" />
						</h:selectOneRadio>
						<h:message for="userStatus" style="color:red" />

						<h:panelGroup layout="block" id="contactList">
							<ui:repeat var="itemContact" value="#{userBean.user.contactList}">
								<h:outputLabel value="#{itemContact.type.name}" />
								<h:outputLabel value="#{itemContact.content}" />
							</ui:repeat>
						</h:panelGroup>
					</h:panelGrid>

					<h:panelGroup layout="block">
						<p:commandButton value="Salvar--- BUNDLE" update="@form"
							ajax="true" action="#{userBean.save()}" />
						<br />
						
						<p:commandLink oncomplete="deleteConfirmDlg.show()">
							<f:setPropertyActionListener value="#{userBean.user}"
							target="#{userBean.user}" />
								<p:graphicImage id="imgBtDeleteUser" width="16" styleClass="imgUser"
								value="#{resource['default/images:coringa.png']}"
								title="Excluir --- BUNDLE" />
						</p:commandLink>
															
						<br/>
						
						<p:commandButton value="+" immediate="true" update="contactList" process="@this"
							onclick="dlgContact.show()" action="#{userBean.addContact()}" />
							<f:validateBean disabled="true">
				<p:confirmDialog id="deleteConfirmDialog"  message="Are you sure?"
							header="Delete user" severity="alert"
							widgetVar="deleteConfirmDlg" appendToBody="false">

							<h:form>
								<p:commandButton id="confirmDelete" value="Yes --BUNDLE" action="#{userBean.redirect('userList')}"
									oncomplete="deleteConfirmDlg.hide()"
									actionListener="#{userBean.delete()}" />
								<p:commandButton id="declineDelete" value="Não ---BUNDLEo"
									onclick="deleteConfirmDlg.hide()" type="button" />
							</h:form>
							
						</p:confirmDialog>
						</f:validateBean>								
					</h:panelGroup>
					
					

				</h:panelGroup>

				<br />

			</h:form>

		</h:panelGroup>

	</ui:define>
	<ui:define name="pops">

		<p:dialog id="panelEdit" widgetVar="dlgContact" resizable="false" closable="false" showHeader="false"  
			position="center" modal="true" showEffect="clip" hideEffect="fold">

			<ui:include src="contactEdit.xhtml">
				<ui:param name="idRender" value=":insertUserForm:contactList"/>
			</ui:include>

		</p:dialog>


	</ui:define>
</ui:composition>

